using System.Windows.Forms;
using NUnit.Framework;
using ShadeTree.Binding.Elements;
using ShadeTree.Binding.Settings;
using ShadeTree.Binding.Validation;

namespace ShadeTree.Binding.Tests.Elements
{
    [TestFixture]
    public class TextEditingElementExpressionTester
    {
        #region Setup/Teardown

        [SetUp]
        public void SetUp()
        {
            LastChosenValues.Clear();
        }

        #endregion

        [Test]
        public void When_precision_is_set_the_resultant_string_should_be_formatted_according_to_precision()
        {
            var target = new TextboxTestTarget{Amount = 99};
            var textBox = new TextBox {Text = ""};
            var elem = new TextboxElement(SingleProperty.Build<TextboxTestTarget>(x => x.Amount), textBox);
            var expression = new TextEditingElementExpression(elem).ThePrecisionIs(4);

            elem.Bind(target);

            textBox.Text.ShouldEqual("99.0000");
        }

        [Test]
        public void When_precision_is_set_the_resultant_string_should_be_formatted_according_to_precision_when_the_element_is_a_label()
        {
            var target = new TextboxTestTarget { Amount = 99 };
            var label = new Label { Text = "" };
            var elem = new LabelElement(SingleProperty.Build<TextboxTestTarget>(x => x.Amount), label);
            var expression = new TextEditingElementExpression(elem).ThePrecisionIs(4);

            elem.Bind(target);

            label.Text.ShouldEqual("99.0000");
        }


        internal class TextboxTestTarget
        {
            public double Amount { get; set; }

            public int Age { get; set; }

            [MaximumStringLength(10)]
            public string Name { get; set; }


            public string LastName { get; set; }
        }
    }
}